package com.yc.home.cloudother.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yc.entity.Makeno;
import com.yc.home.cloudother.mapper.MakenoMapper;
import com.yc.home.cloudother.service.IMakenoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lzk
 * @since 2024-09-26
 */
@Service
public class MakenoServiceImpl extends ServiceImpl<MakenoMapper, Makeno> implements IMakenoService {

    @Autowired
    MakenoMapper makenoMapper;

    //新增错题集
    @Override
    public void add(String uid, String qid, String tid, String answer) {
        //判断有没有记录
        LambdaQueryWrapper<Makeno> lqw = new LambdaQueryWrapper<>();
        lqw.eq(Makeno::getUid, uid);
        lqw.eq(Makeno::getQid, qid);
        Makeno makeno = makenoMapper.selectOne(lqw);
        if(makeno == null){
            //没有值
            Makeno makeno1 = new Makeno();
            makeno1.setUid(Integer.valueOf(uid));
            makeno1.setQid(Integer.valueOf(qid));
            makeno1.setTid(Integer.valueOf(tid));
            makeno1.setAnswer(answer);
            makenoMapper.insert(makeno1);
        }else{
            makeno.setAnswer(answer);
            makenoMapper.updateById(makeno);
        }
    }
}
